<?php
/**
 * Comments module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/commentsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         comments
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: action.ajax.php Sat Jul 18 20:17:46 CST 2009
 */

include "header.php";
//$GLOBALS["xoops"]->services["logger"]->activated = false ;
$op = isset($_POST["op"]) ? trim($_POST["op"]) : "";
$ac = isset($_POST["ac"]) ? trim($_POST["ac"]) : "";
$ret = false;
if ( empty($xoopsUser) || !is_object($xoopsUser) ) {
    echo $ret;
    exit();
}
$comments_handler = xoops_getmodulehandler("comments","comments");
switch ($op) {
    case "comment":
        $com_itemid = isset($_POST["com_itemid"]) ? intval($_POST["com_itemid"]) : 0;
        $module = isset($_POST["com_module"]) ? trim($_POST["com_module"]) : "";
        $com_text = isset($_POST["com_text"]) ? trim($_POST["com_text"]) : "";
        $com_title = isset($_POST["com_title"]) ? trim($_POST["com_title"]) : "";
        
        $com_status = isset($_POST["com_status"]) ? intval($_POST["com_status"]) : 0;
        $module_handler = xoops_gethandler("module");
		$_module_obj = $module_handler->getByDirname($module);
		$com_modid = $_module_obj->getVar("mid");
        switch ($ac) {
            case "create":
            default:
                if ( empty($com_text) || empty($com_itemid) ) {
                    $ret = false;
                    echo $ret;
                    exit();
                }
                if ( $com_id = $comments_handler->setComment(0, $com_modid, $com_itemid, $xoopsUser->getVar("uid"), $com_title, $com_text,$com_status) ) {
                    $ret = true;
                } else {
                    $ret = false;
                }
                echo $ret;
                exit();
            break;
        }
    break;
    
    case "delcom":
        $com_id = isset($_POST["com_id"]) ? intval($_POST["com_id"]) : 0;
        $_obj = $comments_handler->get($com_id);
        if ( $_obj->getVar("com_uid") != $xoopsUser->getVar("uid") ) {
            echo $ret;
            exit();
        }
        if ( $comments_handler->delete($_obj) ) {
            echo true;
            exit();
        } else {
            echo false;
            exit();
        }
    break;
    
    default:
        $ret = false;
        echo $ret;
        exit();
    break;
}
?>